<?php
include_once '../../__global.php';

class aj_getAttitudeByRid extends ml_controller
{
    private $_page;
    private $_offset;
    private $_att;
    private $_rid;
    private $_oid;
    private $_aid;
    static $attiWord = array(0 => '可以有',
                            1 => '长草了',
                            2 => '不感冒',
                            3 => '喜欢',);
    
    
    function initParam() {
        $this->_page = $this->input('page','G',1);
        $this->_rid = $this->input('rid','G',0);
        $this->_att = $this->input('att','G',null);
        $this->_oid = $this->input('oid','G',0);
        $this->_offset = $this->input('num','G', 4);
        $this->_aid = $this->__visitor['uid'];
    }
    
    function checkParam() {
        $this->check_referer();
        if (!ml_tool_resid::is_resid($this->_rid)) {
            $this->api_output(ML_RCODE_PARAM);
        }
        
        if (!ml_tool_isuid::is_mluid($this->_oid)) {
            $this->api_output(ML_RCODE_PARAM);
        }
        
        if (!ml_tool_resid::resid2uid($this->_rid) == $this->_oid) {
            $this->api_output(ML_RCODE_PARAM);
        }
        
        if (30 < $this->_page && 0 > $this->_page) {
            $this->api_output(ML_RCODE_PARAM);
        }
        
        if (0 >= $this->_offset) {
            $this->api_output(ML_RCODE_PARAM);
        }
        
    }
    
    function main() {
        
        $begin = ($this->_page- 1)* $this->_offset;
        $num = $this->_offset;
        
        $oLikeMe = new ml_model_dbLikeMe();
        $rs = $oLikeMe->getListByRid($this->_oid, $this->_rid, $begin, $num, $this->_att, $list);
        if (!$rs) {
            $this->api_output(ML_RCODE_BUSY);
        }
        
        $oUAcount = new ml_model_dbUserAccount();
        $dataU = array();
        
        $ordsCount = new ml_model_rdsCount();
        $re = $ordsCount->getAttitudeCount(array($this->_rid));
        if ($re === false) {
            $rs = $oLikeMe->countContentAttUser($this->_oid, $this->_rid, $count);
        } else {
            $count = $ordsCount->get_data();
            $count = $count[$this->_rid];
        }
        $count = intval($count);
        
        foreach($list as $val){
            $uids[]=$val['act_uid'];
        }
        $nicks=ml_tool_nick::uids2nicks($uids);
        
        foreach ($list as $value) {
            $rs = $oLikeMe->sumUserAttScore($value['act_uid'], $score);
            $user['voteNumber'] = $rs ? $score : 0;
            $user['nick']=$nicks[$value['act_uid']];
            if(empty($user['nick'])){
                $rs = $oUAcount->getAccountById($value['act_uid']);
                $user['nick'] = $rs? $rs['nickname'] : '';
            }
            $user['uid'] = $value['act_uid'];
            
            $user['headPic'] = ml_tool_picid::pid2url($value['act_uid'], ML_HEADER_PICSIZE_30, ML_PICTYPE_HEADER);
            $user['ctime'] = ml_tool_standardShow::time($value['ctime']);
            $user['score'] = $value['attitude'];
            $user['attiWord'] = self::$attiWord[$value['attitude']];
            $user['isExpert'] = false;
            $user['followState'] = false;    
            
            $dataU[] = $user;
        }
        
        
        $data['result'] = $dataU;
        $data['totalNum'] = $count;
        $this->api_output(ML_RCODE_SUCC, $data);
        
        
    }
    
    
}

new aj_getAttitudeByRid();